import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
import { CpasIcon, DevGrid } from "~/public/cpas-ui";
import AntTabs from "~/public/cpas-ui/components-ui/ant-components/AntTab";
import { Input, Select } from "antd";
import { LoadPanel, Scrolling, Sorting } from "devextreme-react/data-grid";
import React from "react";
import { SearchOutlined } from "@ant-design/icons";
import { getDevTableData, getReportData, getReportMenu, getCorpData, } from "../../classes/HandSonGridToolService/getDataSourceService";
import CpasTable from "../..";
import { getYears } from "../../../../tools/Tools";
import { dbname } from "../../classes/HandSonGridToolService/pubDbname";
import { formatNumberField, formatDateField, isJSONStr, } from "../../../ExcelGrid/Tools";
import { SelectBox } from "devextreme-react";
import { consts } from "../../../../tools/consts";
import { msgError } from "./msg";
export default class CellData extends React.Component {
    newCpas;
    newColumn1; // 用于更新dev表的新表头
    newColumn2;
    newListData1;
    newListData2;
    tabName;
    inpRef;
    inpRef2;
    // digaoSelctOne: any;
    qsyDefault; // 取数源默认值
    devGridRef2;
    tyear;
    colDatas;
    yearInp1;
    yearInp2;
    cpasData2;
    currentMainCpasData = null;
    menuToolRef;
    newProps;
    constructor(props) {
        super(props);
        console.log("888---cell -props", props);
        this.newCpas = React.createRef();
        this.inpRef = React.createRef();
        this.inpRef2 = React.createRef();
        this.devGridRef2 = React.createRef();
        this.createRelation = this.createRelation.bind(this);
        this.AccountTabsClick = this.AccountTabsClick.bind(this);
        this.devTableDbck = this.devTableDbck.bind(this);
        this.changeInp1 = this.changeInp1.bind(this);
        this.changeInp2 = this.changeInp2.bind(this);
        this.selDataSource1 = this.selDataSource1.bind(this);
        this.selDataSource2 = this.selDataSource2.bind(this);
        this.cpasCellCK = this.cpasCellCK.bind(this);
        this.DigaoItem = this.DigaoItem.bind(this);
        this.refresh1 = this.refresh1.bind(this);
        this.refresh2 = this.refresh2.bind(this);
        this.defaultSelectCell = this.defaultSelectCell.bind(this);
        this.isNumeric = this.isNumeric.bind(this);
        this.menuToolRef = this.props.menuToolRef;
        this.state = {
            // devTableList: [],
            tabText1: "",
            proName: "",
            valParam1: "",
            valParam2: "",
            valName1: consts.ThisYear,
            valName2: consts.ThisYear,
            defaultVal: "",
            rowVal3: "",
            activeIndex3: 0,
            dataSource1: "",
            dataSource2: "",
            columnsData: this.props.columnsData,
            listData: this.props.listData,
            oneHeaders: [],
            colIndex: 0,
            defLabel: "",
            selVal: "",
            coord: {},
            // cpasData: [],
            cpasData: this.props.cpasData,
            getComDataSoureSelect: [],
            getDiGaoSourceSelect: [],
            getNumberSourceSelect: [],
            formulaVal: "=FS_CELL",
            getYearsVal: [],
            curYear: "",
            tab2Column: [],
            tab2listData: [],
            selectedValue: "",
            qsyDefaultVal: "",
            qsyDefaultVal2: "",
            getYearVal: "",
            qiyeYear: consts.ThisYear,
            digaoYear: consts.ThisYear,
            stateListData2: [],
            stateColumn2: [],
            tabNames: consts.ReportTabKey,
            yearVals: consts.ThisYear,
            projectName1: "",
            projectName2: "",
        };
    }
    //默认选中单元格
    defaultSelectCell() {
        const selected = this.props.cpasRef.hot.getSelectedLast();
        if (!selected) {
            return;
        }
        const [startRow, startCol, endRow, endCol] = selected;
        this.newCpas.current.hot.selectCell(startRow, startCol);
        const formula = this.props.cpasRef.hot.getSourceDataAtCell(startRow, startCol);
        let isFormula = false;
        if (typeof formula === "string" && formula.startsWith("=")) {
            if (formula.includes("FS_CELL")) {
                isFormula = true;
            }
            else if (formula.includes("CP_CELL")) {
                isFormula = true;
            }
        }
        if (isFormula) {
            this.setState({
                formulaVal: formula,
            });
            this.cpasCellCK(this.props, this.props.cellCoords);
        }
        else {
            this.setState({
                formulaVal: "=FS_CELL",
            });
        }
    }
    // cpas dev 关系建立：
    createRelation(sourceMap, dataListMap) {
        let relationArr = {};
        relationArr = {
            sourceMap: sourceMap,
            dataListMap: dataListMap,
        };
        return relationArr;
    }
    // tab 页签名称
    async AccountTabsClick(activeKey) {
        this.menuToolRef.setState({
            cellTabsActiveKey: activeKey,
        });
        this.tabName = activeKey;
        this.setState({
            tabNames: activeKey,
        });
        if (activeKey === consts.WpTabKey) {
            let updateValues = await this.getDiGaoOption(); // 底稿结构化数据 - 底稿名称 异步获取的要返回这个值来后面的代码使用
            this.props.activeTab2(consts.WpTabKey);
            this.DigaoItem(updateValues.selectedValue, undefined, this.state.valName2); //这个代码也很关键，它可以让切换过来的tab页执行默认的值接口
            //this.DigaoItem(this.state.selectedValue); //这个代码也很关键，它可以让切换过来的tab页执行默认的值接口
            // this.interfaceDiGaoListData(
            //   this.state.dataSource2,
            //   this.state.valParam2,
            //   dbname,
            //   [],
            //   "",
            //   "",
            //   false,
            //   0
            // );
            // this.interfaceDiGaoHeader(
            //   this.state.dataSource2,
            //   this.state.valParam2,
            //   dbname,
            //   [],
            //   "",
            //   "",
            //   true,
            //   0
            // );
        }
        if (activeKey === consts.ReportTabKey) {
            this.props.activeTab1(consts.ReportTabKey);
        }
    }
    // 上面动态弹窗 数据点击交互事件,
    ckRowData(e, index, item) {
        this.setState({
            rowVal3: item.label, // 拿到当前所点击的标签列名
        });
    }
    isNumeric(str) {
        return !isNaN(parseFloat(str)) && isFinite(str);
    }
    /**
     * 通过this.state.getComDataSoureSelect来获取是那个数据源
     * @param formulaSource 公式数据源 base.reportItems base.subjectSDB
     */
    getTabKeyByFormulaSource(formulaSource) {
        let dataSourceArray = this.state?.getComDataSoureSelect || [];
        if (dataSourceArray.length === 0)
            return consts.ReportTabKey;
        return dataSourceArray.some((item) => item.value === formulaSource)
            ? consts.ReportTabKey
            : consts.WpTabKey;
    }
    getHyperCustomFormulaParams(formula) {
        const firstOpeningParenthesisIndex = formula.indexOf("(") + 1;
        const lastClosingParenthesisIndex = formula.lastIndexOf(")");
        const params = formula
            .substring(firstOpeningParenthesisIndex, lastClosingParenthesisIndex)
            .split(",");
        return params;
    }
    //cpas-table 鼠标点击事件
    async cpasCellCK(e, param) {
        console.log("888---cpas表单击", e, param);
        try {
            this.props.getCoord(param);
            this.setState({
                coord: param,
            });
            let data = await getReportMenu();
            // let uniqueData = data.reduce((acc, curr) => {
            //   if (
            //     acc.findIndex((item) => item.ReportItem === curr.ReportItem) === -1
            //   ) {
            //     acc.push(curr);
            //   }
            //   return acc;
            // }, []);
            let uniqueData = data;
            // 处理公式编辑回显
            let reviewData = this.props.cpasData.data;
            let list = reviewData[param.row];
            let formulaVal = `=FS_CELL`;
            if (list) {
                let delData = list && list.slice(param.col);
                if (delData) {
                    if (delData[0]) {
                        let values = this.getHyperCustomFormulaParams(delData[0]);
                        if (values && isJSONStr(values[0])) {
                            let formulaSourceName = JSON.parse(values[0]); //公式取数源,如 base.reportItems
                            let yearTag = JSON.parse(values[3]); //本年标记
                            //批量更新的对象
                            let updateValues = {
                                formulaVal: `=FS_CELL(${values[0]},${values[1]},${values[2]},${values[3]})`,
                            };
                            /* this.setState({
                              formulaVal: `=FS_CELL(${values[0]},${values[1]},${values[2]},${values[3]})`,
                            }); */
                            //****** 以下 为点击有公式的单元格后，切换到对应的取数源和年度下拉 */
                            let yearValue = await getYears(yearTag); //年度值
                            let tabKey = this.getTabKeyByFormulaSource(formulaSourceName);
                            updateValues.tabNames = tabKey; //页签自动切换
                            this.props.activeTab2(tabKey); //返回到父页面
                            this.tabName = tabKey;
                            if (tabKey === consts.ReportTabKey) {
                                //企业基础数据
                                updateValues.dataSource1 = formulaSourceName;
                                // 暂时注掉，因为会导致年度取值有问题
                                updateValues.valParam1 = yearValue.toString();
                                updateValues.valName1 = yearTag;
                                this.yearInp1 = yearTag; //要调接口加检索功能
                                this.interfaceQiYeListData(formulaSourceName, updateValues.valParam1, dbname, [], "", "", false, 0);
                                this.interfaceQiYeHeader(formulaSourceName, updateValues.valParam1, dbname, [], "", "", true, 0);
                            }
                            else if (tabKey === consts.WpTabKey) {
                                //底稿结构化数据
                                //如果底稿列表还没有加载,加载它
                                if (!this.state?.getDiGaoSourceSelect ||
                                    this.state.getDiGaoSourceSelect.length === 0) {
                                    await this.getDiGaoOption();
                                }
                                let formulaSourcePrefix = formulaSourceName.substring(0, 3); //取数源的前面3位,来获取底稿的名称
                                let filteredData = uniqueData.filter((item) => item.ReportItemCode === formulaSourcePrefix);
                                //找到底稿名称
                                if (filteredData.length > 0) {
                                    updateValues.selectedValue = filteredData[0].ReportItem; //底稿名称
                                    updateValues.dataSource2 = formulaSourceName; //数据源名称
                                    this.DigaoItem(updateValues.selectedValue, formulaSourceName, yearTag);
                                }
                                else {
                                    return msgError(`底稿结构化数据错误,未获取到公式 ${formulaSourceName} 的底稿名称`);
                                }
                                updateValues.valParam2 = yearValue.toString();
                                updateValues.valName2 = yearTag;
                                this.yearInp2 = yearTag;
                            }
                            this.setState(updateValues); //执行批量
                            return;
                        }
                    }
                }
            }
            this.setState({
                formulaVal: formulaVal,
            });
        }
        catch (err) {
            console.error(err);
        }
    }
    // 点击列，拿到当前列值,并创建关联关系进行保存
    devTableDbck(e) {
        console.log("888--双击dev表-CpasTable", this.state.dataSource1, this.state.dataSource2, this.state.tabNames);
        const [row, col] = this.newCpas.current?.hot.getSelectedLast();
        this.props.cpasData.data.map((item, n) => {
            if (this.state.coord) {
                if (n === row) {
                    if (this.state.dataSource1 &&
                        this.state.tabNames === consts.ReportTabKey) {
                        // this.newCpas.current.setCellData(
                        //   this.state.coord,
                        //   `=FS_CELL("${this.state.dataSource1}","${e.values[0]}","${e.column.caption}","${this.state.valName1}")`
                        // );
                        // this.newCpas.current.hot.render();
                        if (e.key["主键"]) {
                            item.splice(col, 1, `=FS_CELL("${this.state.dataSource1}","${e.key["主键"]}","${e.column.caption}","${this.state.valName1}")`);
                            // setCellData(coords,value); 根据坐标设置单元格值；  coords:{row:number,col:number}
                            // 英文 取数公式拼接
                            this.setState({
                                formulaVal: `=FS_CELL("${this.state.dataSource1
                                    ? this.state.dataSource1
                                    : this.state.qsyDefaultVal}","${e.key["主键"]}","${e.column.caption}","${this.state.valName1}")`,
                            });
                        }
                    }
                    if ((this.state.dataSource2 || this.state.qsyDefaultVal2) &&
                        this.state.tabNames === consts.WpTabKey) {
                        console.log("888--进tab2");
                        if (e.key["主键"]) {
                            item.splice(col, 1, `=FS_CELL("${this.state.dataSource2
                                ? this.state.dataSource2
                                : this.state.qsyDefaultVal2}","${e.key["主键"]}","${e.column.caption}","${this.state.valName2}")`);
                            //取数公式拼接     // FS_CELL("fa.mxb","1003","原值期初未审","2017")
                            this.setState({
                                formulaVal: `=FS_CELL("${this.state.dataSource2
                                    ? this.state.dataSource2
                                    : this.state.qsyDefaultVal2}","${e.key["主键"]}","${e.column.caption}","${this.state.valName2}")`,
                            });
                        }
                    }
                }
            }
            return item;
        });
        // 通过双击，实时刷新上面cpas表中的数据
        this.newCpas.current.reloadTable(this.props.cpasData);
    }
    //******** 检索条件接口调用 start */
    //企业基础数据 -- 取数源
    async EnterpriseBaseData() {
        try {
            let data = await getCorpData();
            // 需要转化一下格式
            const transferData = data.map((item) => {
                return { label: item.dataSrcName, value: item.dmName };
            });
            this.setState({
                getComDataSoureSelect: transferData,
                qsyDefaultVal: transferData[0].value,
                dataSource1: data[0].dmName,
            });
            this.qsyDefault = data[0].dataSrcName;
            this.props.getTbname1(transferData[0].value);
            //自执行接口，this.state.getComDataSoureSelect[0].dmName
            const result = await getYears(consts.ThisYear);
            this.interfaceQiYeListData(transferData[0].value, result.toString(), dbname, [], "", "", false, 0);
            this.interfaceQiYeHeader(transferData[0].value, result.toString(), dbname, [], "", "", true, 0);
        }
        catch (err) {
            console.error(err);
        }
    }
    //******** 检索条件接口调用 end */
    // tab1--取数源 下拉框 取值
    async selDataSource1(val, item) {
        try {
            this.props.getTbname1(val);
            this.setState({
                dataSource1: val,
                defaultVal: item.label,
                defLabel: item.value,
                qsyDefaultVal: val, // 默认值改变
            });
            let result = await getYears(consts.ThisYear);
            this.interfaceQiYeListData(val, this.state.valParam1 ? this.state.valParam1 : result.toString(), dbname, [], "", "", false, 0);
            this.interfaceQiYeHeader(val, this.state.valParam1 ? this.state.valParam1 : result.toString(), dbname, [], "", "", true, 0);
        }
        catch (err) {
            console.error(err);
        }
    }
    async selDataSource2(val, item) {
        console.log("888--selDataSource2", val, item, this.state.dataSource2);
        try {
            this.props.getTbname2(val);
            this.setState({
                dataSource2: val,
                defaultVal: item.label,
                defLabel: item.value, // 英文参数
            });
            let result = await getYears(consts.ThisYear);
            await this.interfaceDiGaoHeader(val, this.state.valParam2 ? this.state.valParam2 : result.toString(), dbname, [], "", "", true, 0);
            await this.interfaceDiGaoListData(val, this.state.valParam2 ? this.state.valParam2 : result.toString(), dbname, [], "", "", false, 0);
        }
        catch (error) {
            console.error(error);
        }
    }
    // 底稿结构化数据 -- 底稿名称 -options 转换 getDiGaoDataSelect
    async getDiGaoOption() {
        let data = await getReportMenu();
        // let uniqueData = data.reduce((acc, curr) => {
        //   if (acc.findIndex((item) => item.ReportItem === curr.ReportItem) === -1) {
        //     acc.push(curr);
        //   }
        //   return acc;
        // }, []);
        let uniqueData = data;
        // 转化数据格式，展示下拉框
        const transferData = uniqueData.map((item) => {
            return { label: item.ReportItem, value: item.ReportItem };
        });
        let updateValues = {
            getDiGaoSourceSelect: transferData,
            selectedValue: transferData[0].label, // 底稿名称默认值
        };
        // 执行取数源列表接口
        this.DigaoItem(transferData[0].label); // 底稿名称默认有值的时候，取数源下拉数据也要默认有的，但是不选中
        // 此代码有用，后期再测试功能 当itemName存在时，底稿名称下拉框要默认对应上去
        if ((this.tabName = consts.WpTabKey && this.props.itemName)) {
            // 左边树节点点击拿到的报表项目名称和底稿名称对应在上去。就默认出来
            transferData.filter((item) => {
                if (item.label === this.props.itemName) {
                    updateValues.selectedValue = this.props.itemName;
                    /*
                    this.setState({
                      selectedValue: this.props.itemName,
                    }); */
                }
                else {
                    updateValues.selectedValue = transferData[0].label;
                    /*  this.setState({
                       selectedValue: transferData[0].label,
                     }); */
                }
            });
        }
        else {
            updateValues.selectedValue = transferData[0].label;
            /*  this.setState({
              selectedValue: transferData[0].label,
            }); */
        }
        this.setState(updateValues);
        return updateValues;
    }
    // 底稿结构化数据 - 取数源下拉 （底稿名称 触发事件）
    //digaoName: 选择的底稿名称
    async DigaoItem(digaoName, formulaSourceName, yearTag) {
        try {
            this.props.getDigaoName(digaoName);
            this.setState({ selectedValue: digaoName });
            let data = await getReportData(digaoName);
            const items = data.map((item) => {
                return { label: item.dataSrcName, value: item.dmName };
            });
            if (!items || items.length === 0) {
                return msgError("没有获取到底稿 " + digaoName + " 的数据源列表.");
            }
            formulaSourceName = formulaSourceName || items[0].value;
            this.setState({
                getNumberSourceSelect: items,
                qsyDefaultVal2: formulaSourceName,
                dataSource2: formulaSourceName, // 决定着单元格取数的公式回显的时侯，底稿名称切换，取数源表默认是第一个值 */
            });
            console.log("888--底稿名称切换", this.state.dataSource2, items[0].value);
            this.props.getTbname2(formulaSourceName);
            yearTag = yearTag || consts.ThisYear; // || this.state.valParam2 ||
            const yearValue = await getYears(yearTag);
            await this.interfaceDiGaoHeader(formulaSourceName, yearValue, dbname, [], "", "", true, 0);
            await this.interfaceDiGaoListData(formulaSourceName, yearValue, dbname, [], "", "", false, 0);
        }
        catch (error) {
            console.error(error);
        }
    }
    //年度-触发年度下拉框取出值
    async selYear1(val) {
        console.log("888-syearVals111", val);
        try {
            const result = await getYears(val.value);
            this.props.getYearVal(result.toString()); // 属性传值
            this.props.getYearSel1(val.value);
            this.setState({
                valParam1: result.toString(),
                valName1: val.value,
                yearVals: val.value,
            });
            this.interfaceQiYeListData(this.state.dataSource1
                ? this.state.dataSource1
                : this.state.qsyDefaultVal, result.toString(), dbname, [], "", "", false, 0);
            this.interfaceQiYeHeader(this.state.dataSource1
                ? this.state.dataSource1
                : this.state.qsyDefaultVal, result.toString(), dbname, [], "", "", true, 0);
        }
        catch (error) {
            console.error(error);
        }
    }
    async selYear2(val) {
        console.log("888--change--year2", val);
        try {
            const result = await getYears(val.value);
            this.props.getYearVal(result.toString());
            this.props.getYearSel2(val.value);
            this.setState({
                valParam2: result.toString(),
                valName2: val.value,
                yearVals: val.value,
            });
            await this.interfaceDiGaoHeader(this.state.dataSource2
                ? this.state.dataSource2
                : this.state.qsyDefaultVal2, result.toString(), dbname, [], "", "", true, 0);
            await this.interfaceDiGaoListData(this.state.dataSource2
                ? this.state.dataSource2
                : this.state.qsyDefaultVal2, result.toString(), dbname, [], "", "", false, 0);
        }
        catch (error) {
            console.error(error);
        }
    }
    // 封装的模糊检索方法
    // fuzzyQuery(list, keyWord) {
    //   var arr = [];
    //   for (var i = 0; i < list.length; i++) {
    //     if (list[i].项目 && list[i].项目.indexOf(keyWord) >= 0) {
    //       arr.push(list[i]);
    //     }
    //     if (list[i].项目名称 && list[i].项目名称.indexOf(keyWord) >= 0) {
    //       arr.push(list[i]);
    //     }
    //   }
    //   return arr;
    // }
    // 封装的模糊检索方法 -- 2023.7.10 下午14:45 邵宏和我定的按‘主键’搜索
    fuzzyQuery(list, keyWord) {
        var arr = [];
        for (var i = 0; i < list.length; i++) {
            if (list[i].主键 && list[i].主键.indexOf(keyWord) >= 0) {
                arr.push(list[i]);
            }
        }
        return arr;
    }
    // 项目名称
    async changeInp1(e) {
        try {
            console.log("888--changeInp1", e);
            this.props.getProjectName1(e.target.value);
            this.setState({
                proName: this.inpRef.current.input.value,
            });
            let result = await getYears(consts.ThisYear);
            this.interfaceQiYeListData(this.state.dataSource1
                ? this.state.dataSource1
                : this.state.qsyDefaultVal, this.state.valParam1 ? this.state.valParam1 : result.toString(), dbname, [], "", "", false, 0);
            this.interfaceQiYeHeader(this.state.dataSource1
                ? this.state.dataSource1
                : this.state.qsyDefaultVal, this.state.valParam1 ? this.state.valParam1 : result.toString(), dbname, [], "", "", true, 0);
        }
        catch (err) {
            console.error(err);
        }
    }
    async changeInp2(e) {
        try {
            this.setState({
                proName: this.inpRef2.current.input.value,
            });
            // this.props.getProjectName2(e.target.value);
            let result = await getYears(consts.ThisYear);
            await this.interfaceDiGaoHeader(this.state.dataSource2
                ? this.state.dataSource2
                : this.state.qsyDefaultVal2, this.state.valParam2 ? this.state.valParam2 : result.toString(), dbname, [], "", "", true, 0);
            await this.interfaceDiGaoListData(this.state.dataSource2
                ? this.state.dataSource2
                : this.state.qsyDefaultVal2, this.state.valParam2 ? this.state.valParam2 : result.toString(), dbname, [], "", "", false, 0);
        }
        catch (err) {
            console.error(err);
        }
    }
    async refresh1() {
        try {
            let result = await getYears(consts.ThisYear);
            // 刷新一遍接口
            this.interfaceQiYeListData(this.state.dataSource1
                ? this.state.dataSource1
                : this.state.qsyDefaultVal, this.state.valParam1 ? this.state.valParam1 : result.toString(), dbname, [], "", "", false, 0);
            this.interfaceQiYeHeader(this.state.dataSource1
                ? this.state.dataSource1
                : this.state.qsyDefaultVal, this.state.valParam1 ? this.state.valParam1 : result.toString(), dbname, [], "", "", true, 0);
        }
        catch (err) {
            console.error(err);
        }
    }
    async refresh2() {
        try {
            let result = await getYears(consts.ThisYear);
            await this.interfaceDiGaoHeader(this.state.dataSource2
                ? this.state.dataSource2
                : this.state.qsyDefaultVal2, this.state.valParam2 ? this.state.valParam2 : result.toString(), dbname, [], "", "", true, 0);
            await this.interfaceDiGaoListData(this.state.dataSource2
                ? this.state.dataSource2
                : this.state.qsyDefaultVal2, this.state.valParam2 ? this.state.valParam2 : result.toString(), dbname, [], "", "", false, 0);
        }
        catch (err) {
            console.error(err);
        }
    }
    // 企业基础数据
    async interfaceQiYeListData(tname, data_id, dbName, fields, where, order, queryMeta, top) {
        try {
            let ab = await this.getDevListData_popRow(tname, data_id, dbName, fields, where, order, queryMeta, top);
            if (ab) {
                this.newListData1 = ab.devTableList;
                //模糊检索
                let filterListData = this.fuzzyQuery(this.newListData1, this.inpRef.current.input.value);
                this.newListData1 = filterListData;
                if (this.inpRef.current.input.value === "") {
                    this.newListData1 = ab.devTableList;
                }
                this.forceUpdate();
            }
            else {
                // this.newColumn1 = [];
                this.newListData1 = [];
                this.forceUpdate();
            }
        }
        catch (err) {
            console.error(err);
        }
    }
    // 企业基础数据 -- 拿表头数据类型
    async interfaceQiYeHeader(tname, data_id, dbName, fields, where, order, queryMeta, top) {
        let res = await this.getDevListData_dataTYpe(tname, data_id, dbName, fields, where, order, queryMeta, top);
        console.log("888--res1111", res);
        if (res && res.columnData) {
            formatNumberField(res.columnData);
            // formatDateField(res.columnData);
            this.newColumn1 = res.columnData;
            this.forceUpdate();
        }
    }
    // 底稿结构化数据
    async interfaceDiGaoListData(tname, data_id, dbName, fields, where, order, queryMeta, top) {
        try {
            let ab = await this.getDevListData_popRow(tname, data_id, dbName, fields, where, order, queryMeta, top);
            if (ab) {
                // ab.devTableList = ab.devTableList.map((ele) => {
                //   if (ele.编辑时间) {
                //     ele.编辑时间 = moment(ele.编辑时间).format("YYYY-MM-DD HH:mm:ss");
                //   }
                //   return ele;
                // });
                formatDateField(ab.devTableList);
                this.newListData2 = ab.devTableList;
                console.log(ab.devTableList);
                //模糊检索
                let filterListData = this.fuzzyQuery(this.newListData2, this.inpRef2.current.input.value);
                this.newListData2 = filterListData;
                if (this.inpRef2.current.input.value === "") {
                    this.newListData2 = ab.devTableList;
                }
                this.forceUpdate();
            }
            else {
                // this.newColumn2 = [];
                this.newListData2 = [];
                this.forceUpdate();
            }
        }
        catch (err) {
            console.error(err);
        }
    }
    //底稿结构化表头数据类型
    async interfaceDiGaoHeader(tname, data_id, dbName, fields, where, order, queryMeta, top) {
        // 拿表头数据类型
        let res = await this.getDevListData_dataTYpe(tname, data_id, dbName, fields, where, order, queryMeta, top);
        if (res && res.columnData) {
            formatNumberField(res.columnData);
            // formatDateField(res.columnData, this.newListData2);
            this.newColumn2 = res.columnData;
            this.forceUpdate();
        }
    }
    // 接口调用-
    async getDevListData_popRow(dbName, tname, data_id, fields, where, order, queryMeta, top) {
        let devTableList = [];
        // const columnDas: any = [];
        devTableList = await getDevTableData(dbName, tname, data_id, fields, where, order, queryMeta, 0);
        // if (devTableList && devTableList?.length !== 0) {
        //   // 表格表头，从接口动态取值
        //   for (let i = 0; i < Object.keys(devTableList?.[0])?.length; i++) {
        //     columnDas.push({
        //       dataField: Object.keys(devTableList[0])[i],
        //       caption: Object.keys(devTableList[0])[i],
        //       fixed: false,
        //       width: "150px",
        //     });
        //   }
        // } else {
        //   return false;
        // }
        // columnDas[0].fixed = true; // 冻结主键第一列
        // this.colDatas = columnDas;
        return { devTableList };
    }
    // 接口调用-针对添加数据类型
    async getDevListData_dataTYpe(dbName, tname, data_id, fields, where, order, queryMeta, top) {
        let dataType = [];
        dataType = await getDevTableData(dbName, tname, data_id, fields, where, order, true, 0);
        // if (dataType && dataType?.length !== 0) {
        //   dataType.map((item) => {
        //     this.colDatas?.map((its) => {
        //       if (its.dataField === item.FieldName) {
        //         its.FieldType = item.FieldType;
        //       }
        //     });
        //     return item;
        //   });
        // } else {
        //   return false;
        // }
        let columnData = [];
        dataType.map((item) => {
            columnData.push({
                dataField: item.FieldName,
                caption: item.FieldCaption,
                fixed: false,
                minWidth: "130px",
                maxWidth: "300px",
                FieldType: item.FieldType,
            });
            return item;
        });
        if (columnData.length > 0) {
            columnData[0].fixed = true; // 冻结主键第一列
        }
        this.forceUpdate();
        // this.newListData2 = [];
        console.log("888==columnData", columnData);
        return { dataType, columnData };
    }
    componentDidMount() {
        // this.tabName = consts.ReportTabKey;
        this.EnterpriseBaseData(); // 企业基础数据-取数源
        // this.getDiGaoOption(); // 底稿结构化数据 - 底稿名称
        this.defaultSelectCell(); // 弹窗打开默认选中单元格位置
        if (this.props.cellCoords.row && this.props.cellCoords.col) {
            //执行一下单元格点击操作
            this.cpasCellCK(this.props, this.props.cellCoords);
        }
        //本年 传参到定义公式
        const currentYeardata = getYears(consts.ThisYear);
        currentYeardata.then((result) => {
            this.props.getYearVal(result.toString());
            this.tyear = result.toString();
            this.setState({
                valParam2: result.toString(),
            });
        });
        this.setState({
            tabNames: consts.ReportTabKey,
        });
        this.props.getYearSel1(consts.ThisYear);
        this.props.getYearSel2(consts.ThisYear);
        this.yearInp1 = consts.ThisYear;
        this.yearInp2 = consts.ThisYear;
    }
    async componentWillReceiveProps(nextProps) {
        if (this.currentMainCpasData === null) {
            if (this.props.cpasRef) {
                const currentGridData = this.props.cpasRef.getCpasTableGrid();
                await this.newCpas.current?.reloadTable(currentGridData);
                this.currentMainCpasData = currentGridData;
                setTimeout(() => {
                    this.newCpas.current?.reRender();
                    this.defaultSelectCell(); // 弹窗打开默认选中单元格位置
                }, 300);
            }
        }
        this.newProps = nextProps;
    }
    render() {
        return (_jsxs(_Fragment, { children: [_jsxs("div", { className: "con mb-10", children: [_jsxs("div", { className: "flex-start mb-10", children: [_jsx("div", { className: "f12", children: "\u53D6\u6570\u516C\u5F0F\uFF1A" }), _jsx("div", { style: { width: "90%" }, children: _jsx(Input, { placeholder: "=FS_CELL(\u201C\u62A5\u544A\u57FA\u7840\u6570\u636E \u53D6\u6570\u6E90\u4E0B\u62C9\u201D,\u201Ddev\u8868\u884C\u201D,\u201Ddev\u8868\u5217\u201D,\u201D2017\u5E74\u5EA6\u201D)", value: this.state.formulaVal }) })] }), _jsx("div", { style: { height: "250px", border: "0px solid #000" }, children: _jsx(CpasTable, { ref: this.newCpas, name: "innerTable", type: "ds", formulaTimeSlice: true, isTest: false, gridData: null, isShowMenuToolBar: false, mapColumnsList: [], mapRowsList: [], afterOnCellMouseDown: this.cpasCellCK, numberZeroReplace: " " }) })] }), _jsx("div", { className: "con", children: _jsxs(AntTabs, { tabBarStyle: { background: "#FFF" }, onChange: this.AccountTabsClick, 
                        // activeKey={this.menuToolRef.state.cellTabsActiveKey}
                        activeKey: this.state.tabNames, children: [_jsx(AntTabs.Panel, { tab: consts.ReportTabKey, style: { marginTop: "5px" }, children: _jsxs("div", { children: [_jsxs("div", { className: "flexCon mb-10 f12", children: [_jsxs("div", { className: "flex-start", children: [_jsx("div", { className: "mr-8 nowrap", children: "\u53D6\u6570\u6E90:" }), _jsx("div", { className: "mr-24", id: "self_sty", children: _jsx(Select
                                                            // defaultValue={this.state.qsyDefaultVal}
                                                            // value={this.qsyDefault}
                                                            , { 
                                                                // defaultValue={this.state.qsyDefaultVal}
                                                                // value={this.qsyDefault}
                                                                defaultValue: this.state.dataSource1, value: this.state.dataSource1, style: { width: 180 }, options: this.state.getComDataSoureSelect, onChange: this.selDataSource1 }) }), _jsx("div", { className: "mr-8 nowrap", children: "\u5E74\u5EA6:" }), _jsx("div", { className: "custom_curYear", children: _jsx(SelectBox, { width: 95, dataSource: consts.YearTagList, value: this.state.valName1, onValueChanged: (val) => {
                                                                    this.setState({ valName1: val.value });
                                                                    this.selYear1(val);
                                                                } }) })] }), _jsxs("div", { className: "flex-start", children: [_jsx("div", { className: "mr-8 nowrap", children: "\u9879\u76EE\u540D\u79F0:" }), _jsx("div", { children: _jsx(Input, { style: { height: "30px" }, ref: this.inpRef, size: "small", placeholder: "", 
                                                                // onChange={this.changeInp1}
                                                                // value={this.state.projectName1}
                                                                onPressEnter: this.changeInp1, suffix: _jsx(SearchOutlined, { onClick: (v) => this.changeInp1(v) }) }) }), _jsx("div", { className: "icon_refresh", onClick: this.refresh1, children: _jsx(CpasIcon, { type: "icon-yuefenzhongzhi" }) })] })] }), _jsx("div", { className: "h200", children: _jsxs(DevGrid.RangeTap, { dataSource: this.newListData1, columns: this.newColumn1, 
                                                // defaultColumns={this.newColumn1}
                                                showBorders: true, showRowLines: true, 
                                                // onCellClick={this.devTableDbck}
                                                onCellDblClick: this.devTableDbck, columnMinWidth: 120, columnAutoWidth: true, rtlEnabled: false, children: [_jsx(Sorting, { mode: "none" }), _jsx(Scrolling, { mode: "infinite" }), _jsx(LoadPanel, { enabled: false })] }) })] }) }, consts.ReportTabKey), _jsx(AntTabs.Panel, { tab: consts.WpTabKey, style: { marginTop: "5px" }, children: _jsxs("div", { children: [_jsx("div", { style: { overflow: "auto", width: "100%" }, children: _jsxs("div", { className: "flexCon mb-10 f12", children: [_jsxs("div", { className: "flex-start", children: [_jsx("div", { className: "mr-8 nowrap", children: "\u5E95\u7A3F\u540D\u79F0:" }), _jsx("div", { className: "mr-8 custom_sel", id: "self_sty", children: _jsx(SelectBox, { placeholder: "\u9009\u62E9\u5E95\u7A3F\u540D\u79F0", noDataText: "\u65E0\u6570\u636E", searchEnabled: true, displayExpr: "label", valueExpr: "value", dataSource: this.state.getDiGaoSourceSelect, defaultValue: this.state.selectedValue, value: this.state.selectedValue, onItemClick: (e) => {
                                                                        this.DigaoItem(e.itemData.value, undefined, this.state.valName2);
                                                                        // setTimeout(this.refresh2, 100);
                                                                    }, dropDownOptions: { width: "300px" } }) }), _jsx("div", { className: "mr-8 nowrap", children: "\u53D6\u6570\u6E90:" }), _jsx("div", { className: "mr-8 custom_sel", id: "self_sty", children: _jsx(Select, { defaultValue: this.state.dataSource2
                                                                        ? this.state.dataSource2
                                                                        : this.state.qsyDefaultVal2, value: this.state.dataSource2
                                                                        ? this.state.dataSource2
                                                                        : this.state.qsyDefaultVal2, style: { width: 120 }, options: this.state.getNumberSourceSelect, onChange: this.selDataSource2 }) }), _jsx("div", { className: "mr-8 nowrap", children: "\u5E74\u5EA6:" }), _jsx("div", { className: "custom_sel custom_curYear", children: _jsx(SelectBox, { width: 95, dataSource: consts.YearTagList, value: this.state.valName2, onValueChanged: (val) => {
                                                                        this.setState({ valName2: val.value });
                                                                        this.selYear2(val);
                                                                    } }) })] }), _jsxs("div", { className: "flex-start", children: [_jsx("div", { className: "mr-8 nowrap", children: "\u9879\u76EE\u540D\u79F0:" }), _jsx("div", { children: _jsx(Input, { style: { height: "30px" }, ref: this.inpRef2, size: "small", onPressEnter: this.changeInp2, placeholder: "", 
                                                                    // value={this.state.projectName2}
                                                                    suffix: _jsx(SearchOutlined, { onClick: this.changeInp2 }) }) }), _jsx("div", { className: "icon_refresh", onClick: this.refresh2, children: _jsx(CpasIcon, { type: "icon-yuefenzhongzhi" }) })] })] }) }), _jsx("div", { className: "h200", children: _jsxs(DevGrid.RangeTap, { ref: this.devGridRef2, height: 200, defaultColumns: this.newColumn2, dataSource: this.newListData2, columns: this.newColumn2, 
                                                // dataSource={this.state.stateListData2}
                                                // defaultColumns={this.state.stateColumn2}
                                                showBorders: true, showRowLines: true, showColumnLines: true, rowAlternationEnabled: false, 
                                                // onCellClick={this.devTableDbck}
                                                onCellDblClick: this.devTableDbck, columnMinWidth: 120, columnAutoWidth: true, rtlEnabled: false, children: [_jsx(Sorting, { mode: "none" }), _jsx(Scrolling, { mode: "infinite" }), _jsx(LoadPanel, { enabled: false })] }) })] }) }, consts.WpTabKey)] }) })] }));
    }
}
